package game.screen;

import game.manager.InputManager;
import game.manager.PersonManager;
import game.manager.ScoreManager;
import game.screen.option.ScreenOption;
import game.util.Util;

import java.util.List;

public abstract class Screen {
	protected boolean printed;

	public Screen() {
		this.printed = false;
	}

	protected abstract List<ScreenOption> getOptions();

	public abstract String getTitle();

	public abstract void draw();

	public void print() {
		if (!this.printed) {
			this.printed = true;
			// Print the title
			printTitle();
			// Print the options
			printOptions();
			// Let the user choose an option
			promptInput();
		}
	}

	protected void promptInput() {
		// Get Input
		InputManager.getManager().selectFromOptions(this.getOptions());
	}

	protected void printTitle() {
		printDivider();
		// Title
		Util.print("[" + this.getTitle() + "] "
				+ PersonManager.getManager().getUser().getEnergy() + "E, "
				+ PersonManager.getManager().getUser().getCash() + "$, Score: "
				+ ScoreManager.getManager().getScore() + "\n");
		printDivider();
	}

	protected void printDivider() {
		Util.print("===========================\n");
	}

	protected void printOptions() {
		// Options
		int i = 1;
		for (ScreenOption option : this.getOptions()) {
			if (option.isEnabled())
				Util.print(i + ")" + option.getText() + "\n");
			else
				Util.print("X)" + option.getText() + "\n");
			i++;
		}
		Util.print("\n");
	}

	public void refreshScreen() {
		this.printed = false;
	}
}
